export const githubApiReleasesBaseUrl = 'https://api.github.com/repos/{username}/{repository}/releases/latest';

export const githubReleasesBaseUrl = 'https://github.com/{username}/{repository}/releases';

export type SourceType = {
    title: string,
    username: string,
    repository: string,
    url?: string,
    release?: string,
    version?: string,
    desc?: string
}

export type SourceSimpleType = {
    title?: string,
    username: string,
    repository: string,
    url?: string,
    release?: string,
    version?: string,
    desc?: string
}

let sourceList: SourceType[] = [{
    title: 'nvm-windows',
    username: 'coreybutler',
    repository: 'nvm-windows',
    url: '',
    release: '',
    version: '',
    desc: ''
}]

sourceList = sourceList.map(item => {
    item.url = getCompleteReleasesUrl(item);
    item.release = getCompleteApiReleasesUrl(item);
    return item;
});

export function getCompleteApiReleasesUrl(item: SourceSimpleType) {
    return githubApiReleasesBaseUrl.replace('{username}', item.username).replace('{repository}', item.repository);
}

export function getCompleteReleasesUrl(item: SourceSimpleType) {
    return githubReleasesBaseUrl.replace('{username}', item.username).replace('{repository}', item.repository);
}

export default sourceList;
